package com.software.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.plexus.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.software.dao.impl.MessageDetailDaoImpl;
import com.software.model.DrmAgentImg;
import com.software.model.PageListModel;
import com.software.model.PageModel;
import com.software.service.ImgMngService;
import com.software.utils.Constants;
import com.software.utils.IdCreater;


/**
 * 相册管理Controller
 * @author xuyg
 *
 */
@Controller("imgMngController")
@RequestMapping(value = "/imgMng/*")
public class ImgMngController extends BaseController{

	@Autowired
	private ImgMngService imgMngService;
	
	@Autowired
	private MessageDetailDaoImpl mongo;
	
	/**
	 * 相册管理 添加图片
	 * @param imgData
	 * @param res
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "saveAgentImg",produces = "text/html;charset=UTF-8")
	public ModelAndView picAddInit(@RequestBody DrmAgentImg imgData, HttpServletResponse res, HttpServletRequest req) {
		imgData.setId(IdCreater.getId());
		imgData.setAgentId(super.getUserIdInSession(req));
		imgData.setDelYn(Constants.DEL_NO);
		imgMngService.saveAgentImg(imgData);

		ModelAndView map = new ModelAndView();

		PageModel vo = new PageModel();

		// 默认页面翻页数据加载
		viewPageSet(vo);

		vo.setIds(super.getUserIdInSession(req).toString());
		PageListModel val = imgMngService.searchAgentImgList(vo);
		map.addObject("imgList", val);
		map.setViewName("agent/pic");
		return map;
	}
	
	/**
	 * 相册管理 点击删除
	 * @param imgData
	 * @param res
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "updateImgDel",produces = "text/html;charset=UTF-8")
	public ModelAndView picDel(@RequestBody String id, HttpServletResponse res, HttpServletRequest req){
		DrmAgentImg imgData = new DrmAgentImg();
		if(StringUtils.isNotEmpty(id)){
			imgData.setId(new Long(id));
			imgData.setDelYn(Constants.DEL_YES);
			imgMngService.updateAgentDel(imgData);
		}
		
		 ModelAndView map = new ModelAndView();
		 
		 PageModel vo = new PageModel();
		 
		 // 默认页面翻页数据加载
		 viewPageSet(vo);
	        
		vo.setIds(super.getUserIdInSession(req).toString());
        PageListModel val = imgMngService.searchAgentImgList(vo);
        map.addObject("imgList",  val);
        map.setViewName("agent/pic");
        return map;
	}
	
	/**
	 * 相册管理 点击编辑init
	 * @param imgData
	 * @param res
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "updateImgInit")
	@ResponseBody  
	public DrmAgentImg updateImg(@RequestBody String id, HttpServletResponse res, HttpServletRequest req) {
		PageModel vo = new PageModel();
		vo.setIds(id);
		DrmAgentImg data = imgMngService.searchImgOne(vo);
		data.setHiddenId(id);
		return data;
	}
	
	/**
	 * 相册管理 点击编辑
	 * @param imgData
	 * @param res
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "updateImgData",produces = "text/html;charset=UTF-8")
	public ModelAndView updataImgData(@RequestBody DrmAgentImg imgData, HttpServletResponse res, HttpServletRequest req){
		imgData.setAgentId(super.getUserIdInSession(req));
		imgMngService.updateAgentImg(imgData);
//		
		 ModelAndView map = new ModelAndView();
		 
		 PageModel vo = new PageModel();
		 
		 // 默认页面翻页数据加载
		 viewPageSet(vo);
	        
		vo.setIds(super.getUserIdInSession(req).toString());
        PageListModel val = imgMngService.searchAgentImgList(vo);
        map.addObject("imgList",  val);
        map.setViewName("agent/pic");
        return map;
	}
	
	
	
	
	
	
}
